//
//  GameDetailTableViewCell_Bottom.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/3.
//

#import "GameDetailTableViewCell_Bottom.h"

@interface GameDetailTableViewCell_Bottom ()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *rightImage;

@property (nonatomic, assign) BOOL isOpen;//当前是否展开

@end

@implementation GameDetailTableViewCell_Bottom

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UIView *topView = [[UIView alloc] init];
    topView.clipsToBounds = YES;
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(5);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(20);
    }];
    VHWeakSelf
    [topView addTapBlock:^(id  _Nonnull obj) {
        VHStrongSelf
        [self topPutway];
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.textColor = kThemeTitleColor;
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topView).offset(10);
        make.centerY.equalTo(topView);
    }];
    
    UIImageView *rightImage = [[UIImageView alloc] init];
    [rightImage setImage:[UIImage imageNamed:@"ic_right_orange"]];
    [topView addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(5);
        make.centerY.equalTo(topView);
        make.width.mas_equalTo(5);
        make.height.mas_equalTo(8);
        make.right.equalTo(topView).offset(-10);
    }];
    
    self.topView = topView;
    self.titleLabel = titleLabel;
    self.rightImage = rightImage;
}

- (void)topPutway
{
    _isOpen = !_isOpen;
    [self cellOpenState:_isOpen];
    
    if (self.footerViewBlock) {
        self.footerViewBlock(_isOpen);
    }
}

- (void)initCellIsOpen:(BOOL)isOpen
{
    _isOpen = isOpen;
    [self cellOpenState:isOpen];
}

- (void)cellOpenState:(BOOL)isOpen
{
    if (isOpen) {//已展开，显示收起文字
        self.titleLabel.text = @"收起";
        [self.rightImage setTransform:CGAffineTransformMakeRotation(-M_PI_2)];
    } else {
        self.titleLabel.text = @"展开";
        [self.rightImage setTransform:CGAffineTransformMakeRotation(M_PI_2)];
    }
}


+(CGFloat)height:(GameDetailNewModel *)detailModel
{
    return 30;
}



@end
